package com.newviews.tcmip.common.model;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author ChenLong
 */
@Data
@ApiModel(value = "分页对象", description = "分页对象")
public class PageModel<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value = "当前页码")
    private long pageNo;

    @ApiModelProperty(value = "页大小")
    private long pageSize;

    @ApiModelProperty(value = "总行数")
    private long totalCount;

    @ApiModelProperty(value = "总页码")
    private long totalPage;

    @ApiModelProperty(value = "页数据")
    private List<T> records;

    public PageModel() {
        this.pageNo = 0;
        this.pageSize = 0;
        this.totalCount = 0;
        this.totalPage = 0;
        this.records = null;
    }

    public PageModel(int pageNo, int pageSize, int totalCount, int totalPage, List<T> records) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPage = totalPage;
        this.records = records;
    }

    public PageModel(long pageNo, long pageSize, long totalCount, long totalPage, List<T> records) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPage = totalPage;
        this.records = records;
    }

    public PageModel(IPage page) {
        this.pageNo = page.getCurrent();
        this.pageSize = page.getSize();
        this.totalCount = page.getTotal();
        this.totalPage = page.getPages();
        this.records = page.getRecords();
    }
}
